home *** CD-ROM | disk | FTP | other *** search
- /****
- *
- * These are the routines needed for the actual text-editing functions. They
- * are arranged alphabetically for ease of finding them.
- *
- ***/
-
- # include <types.h>
- # include <errors.h>
- # include <memory.h>
- # include <packages.h>
- # include <quickdraw.h>
- # include <toolutils.h>
- # include <fonts.h>
- # include <windows.h>
- # include <dialogs.h>
- # include <menus.h>
- # include <textedit.h>
- # include <string.h>
- # include <files.h>
- # include <resources.h>
-
- # include <iac.h>
- # define PUBLIC extern
- # include <Editor.h>
-
-
- /**
- * Routine: do_clear
- *
- * This is the routine that carries out the "clear" editing function. It
- * uses the normal TE routine to manipulate the text. In addition, it checks
- * the source extents to see if any of them are affected by it, and if so,
- * it will post the changed extent to the IAC driver for everybody else's
- * use.
- */
-
- # define __SEG__ Main
- void do_clear()
-
- {
- short this_ed; /* edition (updated) */
- short hit_ext; /* extent affect by this call */
- short i; /* scratch */
- short strt, endd; /* range in TE record */
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- extentP extP;
- TEHandle TextH; /* The TextEdit handle */
- Handle ext_data; /* data for extent */
-
- short iac_code = noErr; /* result from IAC call */
- Boolean in_extent = false;
- Boolean ext_killed = false;
-
- extern Boolean chk_extent(); /* sets "current extent" if found */
- extern void kill_extent();
-
- /* get necessary handles, etc. set up */
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- TextH = (**the_data_H).wind_TEH;
- the_extH = (**the_data_H).the_extents;
-
- /* Check extents before actually cutting. Remember which one and we'll
- * update the edition after doing the delete...
- */
- in_extent = chk_extent(TextH, the_extH, (**the_data_H).ext_cnt);
-
- TEDelete (TextH);
- (**the_data_H).dirty = true;
-
- /* if needed, write revised extent to IAC driver */
- if (in_extent) /* this delete affected the extent */
- {
- /* adjust range for extent */
-
- /* If the entire extent was removed, tell IAC driver */
- if (ext_killed)
- {
- iac_code = iac_remove_dependency((**the_data_H).doc_ID,
- (**the_data_H).the_slot,
- curr_ext.hat_check);
- kill_extent(); /* always removes current extent */
- }
- else /* write to driver */
- {
- this_ed = curr_ext.ed_level;
- /* data setup here */
- iac_code = iac_write_data((**the_data_H).doc_ID,
- curr_ext.hat_check,
- &this_ed,
- 1,
- ext_data);
- /* now adjust extent */
- }
- }
- }
-
-
- /**
- * Routine: do_copy
- *
- * This is the routine that carries out the "copy" editing function. It
- * uses the normal TE routine to manipulate the text.
- */
-
- # define __SEG__ Main
- void do_copy()
-
- {
- short this_ed; /* edition (updated) */
- short i; /* scratch */
- short strt, endd; /* range in TE record */
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* hand to extent block */
- extentP extP;
- TEHandle TextH; /* The TextEdit handle */
- Handle ext_data; /* data for extent */
-
- short iac_code = noErr; /* result from IAC call */
- Boolean in_extent = false;
-
- extern Boolean chk_extent(); /* sets "current extent" if found */
-
- /* get necessary handles, etc. set up */
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- TextH = (**the_data_H).wind_TEH;
- the_extH = (**the_data_H).the_extents;
- in_extent = chk_extent(TextH, the_extH, (**the_data_H).ext_cnt);
-
- TECopy (TextH);
- }
-
-
- /**
- * Routine: do_cut
- *
- * This is the routine that carries out the "cut" editing function. It
- * uses the normal TE routine to manipulate the text. In addition, it checks
- * the source extents to see if any of them are affected by it, and if so,
- * it will post the changed extent to the IAC driver for everybody else's
- * use.
- */
-
- # define __SEG__ Main
- void do_cut()
-
- {
- short this_ed; /* edition (updated) */
- short hit_ext; /* extent affect by this */
- short i; /* scratch */
- short strt, endd; /* range in TE record */
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* hand to extent block */
- extentP extP;
- TEHandle TextH; /* The TextEdit handle */
- Handle ext_data; /* data for extent */
- OSErr an_err;
-
- short iac_code = noErr; /* result from IAC call */
- Boolean in_extent = false;
- Boolean ext_killed = false;
-
- extern Boolean chk_extent(); /* sets "current extent" if found */
- extern void kill_extent();
-
- /* get necessary handles, etc. set up */
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- TextH = (**the_data_H).wind_TEH;
- the_extH = (**the_data_H).the_extents;
-
- /* Check extents before actually cutting. Remember which one and we'll
- * update the edition after doing the cut...
- */
- in_extent = chk_extent(TextH, the_extH, (**the_data_H).ext_cnt);
-
- TECut (TextH);
- (**the_data_H).dirty = true;
-
- /* if needed, write revised extent to IAC driver */
- if (in_extent) /* this cut affected the extent */
- {
- /* adjust range for extent */
-
- /* If the entire extent was removed, tell IAC driver */
- if (ext_killed)
- {
- iac_code = iac_remove_dependency((**the_data_H).doc_ID,
- (**the_data_H).the_slot,
- curr_ext.hat_check);
- kill_extent(); /* always removes current extent */
- }
- else /* write to driver */
- {
- HLock((Handle) TextH);
- /* data setup here */
- an_err = PtrToHand (&(**TextH).selStart,
- &ext_data,
- (long) curr_ext.ext_end - curr_ext.ext_strt + 1);
- HUnlock((Handle) TextH);
- this_ed = curr_ext.ed_level;
- iac_code = iac_write_data((**the_data_H).doc_ID,
- curr_ext.hat_check,
- &this_ed,
- 1,
- ext_data);
- } /* end else */
- } /* end in_extent */
- }
-
-
- /**
- * Routine: do_key
- *
- * This is the routine that handles normal typing. It does NOT notify
- * the IAC driver after every keystroke.
- */
-
- # define __SEG__ Main
- void do_key(msg)
- long msg; /* event record message field */
-
- {
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* hand to extent block */
- TEHandle TextH; /* The TextEdit handle */
- char the_ch;
- short e_cnt;
-
- Boolean in_extent = false;
-
- extern Boolean chk_extent();
-
- #define charCodeMask 0x000000FF
- /* copied from event.h to conserve space */
-
- /* get necessary handles, etc. set up */
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- TextH = (**the_data_H).wind_TEH;
- the_extH = (**the_data_H).the_extents;
- the_ch = (char) (msg & charCodeMask);
- e_cnt = (**the_data_H).ext_cnt;
-
- in_extent = chk_extent(TextH, the_extH, e_cnt);
- TEKey(the_ch, TextH);
- (**the_data_H).dirty = true;
-
- /* now adjust extent if necessary */
- if (in_extent)
- {
- if (the_ch==BS) /* backspace - shrink extent */
- {
- curr_ext.ext_end -= 1;
- }
- else /* insertion - expand extent */
- {
- curr_ext.ext_end += 1;
- }
- }
- }
-
-
- /**
- * Routine: do_paste
- *
- * This is the routine that carries out the "paste" editing function. It
- * uses the normal TE routine to manipulate the text. In addition, it checks
- * the source extents to see if any of them are affected by it, and if so,
- * it will post the changed extent to the IAC driver for everybody else's
- * use.
- */
-
- # define __SEG__ Main
- void do_paste()
- {
- short this_ed; /* edition (updated) */
- short hit_ext; /* extent affect by this */
- short i; /* scratch */
- short delta; /* change in extent size */
- short strt, endd; /* range in TE record */
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* hand to extent block */
- TEHandle TextH; /* The TextEdit handle */
- Handle ext_data; /* data for extent */
-
- short iac_code = noErr; /* result from IAC call */
- Boolean in_extent = false;
-
- extern Boolean chk_extent(); /* sets "current extent" if found */
-
- /* get necessary handles, etc. set up */
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- TextH = (**the_data_H).wind_TEH;
- the_extH = (**the_data_H).the_extents;
-
- /* Check extents before actually cutting. Remember which one and we'll
- * update the edition after doing the paste...
- */
- in_extent = chk_extent(TextH, the_extH, (**the_data_H).ext_cnt);
-
- TEPaste (TextH);
- (**the_data_H).dirty = true;
-
- /* if needed, write revised extent to IAC driver */
- if (in_extent) /* this paste affects the extent */
- {
- /* adjust range for extent */
- /* write to driver */
- this_ed = curr_ext.ed_level;
- /* data setup here */
- iac_code = iac_write_data((**the_data_H).doc_ID,
- curr_ext.hat_check,
- &this_ed,
- 1,
- ext_data);
-
- curr_ext.ext_end += delta; /* now update extent */
- curr_ext.ed_level = this_ed;
- }
- }
-
-
- /**
- * Routine: kill_extent
- *
- * This removes the current extent from the table and compresses the
- * table. The count and "active flag" are also updated.
- */
-
- # define __SEG__ Main
- void kill_extent() /* always removes current extent */
- {
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- exTable ext_recs;
- long the_doc; /* local copies due to memory mashing */
- short slot_ID, h_check;
- short e_cnt, startt;
- short i;
-
- short iac_code = noErr; /* result from IAC call */
-
- extern Boolean ext_active;
-
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- the_extH = (**the_data_H).the_extents;
- e_cnt = (**the_data_H).ext_cnt;
- startt = curr_ext.ext_strt;
-
- ext_recs = *the_extH; /* point to table base */
- for (i=0; i<e_cnt; i++)
- {
- if (ext_recs[i].ext_strt == startt) /* found current extent */
- {
- iac_code = iac_remove_dependency((**the_data_H).doc_ID,
- (**the_data_H).the_slot,
- ext_recs[i].hat_check);
- BlockMove(&ext_recs[i+1], /* move tail down */
- &ext_recs[i],
- (e_cnt-i)*sizeof(extent));
- (**the_data_H).ext_cnt -= 1;
- (**the_data_H).dirty = true;
- break;
- }
- }
- ext_active = false;
- }